package route

import (
	"net/http"

	"gitee.com/chewel/hermes/pkg/ginx"
)

type HttpMethod string

func (m *HttpMethod) String() string {
	return string(*m)
}

const (
	GET     HttpMethod = http.MethodGet
	POST    HttpMethod = http.MethodPost
	PUT     HttpMethod = http.MethodPut
	DELETE  HttpMethod = http.MethodDelete
	PATCH   HttpMethod = http.MethodPatch
	HEAD    HttpMethod = http.MethodHead
	OPTIONS HttpMethod = http.MethodOptions
)

type RouterInfo struct {
	Method      HttpMethod
	Pattern     string
	Handler     ginx.HttpHandler
	Middlewares ginx.HttpHandlerClaim
}

func NewRouterInfo(method HttpMethod, pattern string, handler ginx.HttpHandler) *RouterInfo {
	return &RouterInfo{
		Method:      method,
		Pattern:     pattern,
		Handler:     handler,
		Middlewares: make(ginx.HttpHandlerClaim, 0, 8),
	}
}

func (b *RouterInfo) Use(middleware ...ginx.HttpHandler) *RouterInfo {
	b.Middlewares = append(b.Middlewares, middleware...)
	return b
}
